package fr.generali.accueilclient.gwt.showcase.client.form;

import java.util.List;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import com.google.gwt.editor.client.EditorError;
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
import com.google.gwt.validation.client.Validation;

class MyDummyPresenter {

    FormDemo view;
    
    public MyDummyPresenter(FormDemo formDemo) {
        this.view = formDemo;
    }
    
    public void doSomeAction() {
        SimpleBeanEditorDriver<ValidableObject, ?> driver = view.getEditorDriver();

        ValidableObject prospectToCreate = driver.flush();

        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

        Set<ConstraintViolation<ValidableObject>> violations = validator.validate(prospectToCreate);
        
        driver.setConstraintViolations((Iterable<ConstraintViolation<?>>)(Object)(violations));

        List<EditorError> editorErrors = driver.getErrors();
        
        view.setErrors(editorErrors);
    }
    
}